;(function($){
    $.fn.extend({
		"zm_city":function(options){
			options = $.extend({
				"city_json_url":"js/city.json",
				"order_city":"",
				"order_area":""
			},options);
			var order_city = options.order_city;
			var order_area = options.order_area;
			$.getJSON(options.city_json_url,function(data){
				function add_city(){
					$(data).each(function (cityIndex, city){
						var city_option;//城市选项option元素
						if(order_city === city.city_name){
							city_option = '<option value="'+ city.city_name +'" selected>'+ city.city_name +'</option>';//选中的城市列表选项
						}else{
							city_option = '<option value="'+ city.city_name +'">'+ city.city_name +'</option>';
						}
						$("#city").append(city_option);//将城市添加到城市的下拉框中
						
						function add_area(){
							var area_option;//地区选项option元素
							if($("#city").val() === city.city_name){
								$(city.area_list).each(function(areaIndex,area){
									if(order_area === area.area_name){
										area_option = area_option + '<option value="'+ area.area_name +'" selected>'+ area.area_name +'</option>';//选中的地区选项列表
									}else{
										area_option = area_option + '<option value="'+ area.area_name +'" >'+ area.area_name +'</option>';//地区选项列表
									}
									$("#area").html(area_option);//将城市添加到下拉框中
								});
							}
						}
						add_area();
						$("#city").change(function(){
							add_area();
						});
					});
				}
				add_city();//运行城市列表添加函数
			});
		}
	});
})(jQuery);